package com.xbongbong.pro.enums.workflow;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * @author 吴峰
 * @date 2021/05/11 16:02
 */
@Getter
public enum TriggerEventTypeEnum {

    /**
     * 触发事件类型
     */
    ADD_OR_UPDATE(1, "enum.workflow.triggerEventType.add_or_update"),

    ONLY_ADD(2, "enum.workflow.triggerEventType.only_add"),

    ONLY_UPDATE(3, "enum.workflow.triggerEventType.only_update"),

    ONLY_DELETE(4, "enum.workflow.triggerEventType.only_delete"),

    FOR_STAGE(5, "enum.workflow.triggerEventType.for_stage"),

    /**
     * 工单v2
     */
    FOR_WORK_ORDER_V2(9, "enum.workflow.triggerEventType.for_work_order_v2"),


    ;

    private Integer type;

    private String memo;

    TriggerEventTypeEnum(Integer type, String memo) {
        this.type = type;
        this.memo = memo;
    }

    public static String getMemoByType(Integer type) {
        for (TriggerEventTypeEnum triggerEventTypeEnum: values()) {
            if (Objects.equals(triggerEventTypeEnum.getType(), type)) {
                return triggerEventTypeEnum.getMemo();
            }
        }
        return null;
    }

    public String getMemo() {
        return I18nMessageUtil.getMessage(memo);
    }

    /**
     * 根据详细触发事件类型（ 1. 当新增或者更新记录时；2. 仅新增记录时；3.仅更新时；4. 仅删除时；）返回对应的描述
     * @param type
     * @return
     */
    private String getEventInfoByType(Integer type) {
        return TriggerEventTypeEnum.getMemoByType(type);
    }
}
